{layout  name="public:layout" /}
<script src="/static/layer/jquery-2.1.4.min.js"></script>
<link rel="stylesheet" href="/static/layui/css/layui.css"  media="all">
<script type="text/javascript" src="/static/layui/layui.all.js"></script>
<div class="content">

    <div class="header">

        <h1 class="page-title">{$Think.lang.xiugaiquanxian}</h1>
    </div>

    <ul class="breadcrumb">
        <li><a href="#">{$Think.lang.wangzhanguanli}</a> <span class="divider">/</span></li>


        <li><a href="{:url('Role/manage')}">{$Think.lang.quanxianguanli}</a><span class="divider">/</span></li>

        <li class="active">{$Think.lang.xiugaiquanxian}</li>

    </ul>

    <div class="container-fluid">
        <div class="row-fluid">

            <div class="btn-toolbar">
                &nbsp;
                <!--                <a href="#myModal" data-toggle="modal1" class="btn">Delete</a>-->
                <div class="btn-group">
                </div>
            </div>
            <div class="well" style="margin-top: -15px;">
                <!--                <ul class="nav nav-tabs">
                                    <li class="active"><a href="#home" data-toggle="tab">个人信息</a></li>
                                    <li><a href="#profile" data-toggle="tab">修改密码</a></li>
                                </ul>-->



                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form id="form2" name="form" method="post" enctype="multipart/form-data" onsubmit="return false">




                            <label>{$Think.lang.quanxianmingcheng}：</label>
                            <input  name="r_name" type="text" value="{$list.r_name}" class="input-xlarge" style="width: 200px;">
                            <div id="test12" class="demo-tree-more"></div>
                            <input name="r_id" type="hidden" value="{$list.r_id}">



                            <br>
                            <!--<div style="">
                                                            {volist name="flist" id="flist"}
                            
                                                            <br/><input type="checkbox" class="authf" name="auth[]" value="{$flist['auth_id']}" {if condition="in_array($flist['auth_id'],$marr)"}checked='checked'{/if}>&nbsp;<b>{if condition="$a=='zh-cn'"}{$flist.auth_name}{else/}{$flist['auth_en']}{/if}</b><br/>
                                                            <br/>
                            
                                                            {volist name="zlist" id="vo"}
                            
                                                            {if condition="$vo['auth_pid']==$flist['auth_id']"}
                                                            &nbsp;&nbsp;&nbsp;&nbsp;<input class="auth"  type="checkbox" name="auth[]" value="{$vo['auth_id']}" {if condition="in_array($vo['auth_id'],$marr)"}checked='checked'{/if}>&nbsp;{if condition="$a=='zh-cn'"}{$vo.auth_name}{else/}{$vo['auth_en']}{/if}<br/>
                                                            <br/>
                                                            {/if}
                            
                                                            {/volist}
                            
                                                            {/volist}
                               </div>-->
                            <input type="hidden" value="{$jsonarr}" name="jsonarr">

                            <div>
                                &nbsp;<button class="btn btn-primary save1" lay-demo="getChecked"><i class="icon-save"></i> {$Think.lang.baocun}</button>
                            </div>
                        </form>
                        <script>
                            layui.use(['tree', 'util'], function () {
                                //var jsonarr = $("[name=jsonarr]").val(); 


                                var tree = layui.tree
                                        , layer = layui.layer
                                        , util = layui.util
                                        //数据
                                        , data = {$jsonarr};

                                //基本演示
                                tree.render({
                                    elem: '#test12'
                                    , data: data
                                    , showCheckbox: true  //是否显示复选框
                                    , id: 'demoId1'
                                    , isJump: false //是否允许点击节点时弹出新窗口跳转
                                    , click: function (obj) {
                                        //var data = obj.data;  //获取当前点击的节点数据
                                        //layer.msg('状态：' + obj.state + '<br>节点数据：' + JSON.stringify(data));
                                    }
                                });

                                //按钮事件
                                util.event('lay-demo', {
                                    getChecked: function (othis) {
                                        var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
                                        var rid = $("[name=r_id]").val();
                                        var json = JSON.stringify(checkedData);
                                        var r_name = $("[name=r_name]").val();
                                        $.post("{:url('/updatetree')}", {json: json, rid: rid, r_name:r_name}, function (data) {
                                            console.log(data);
                                            if (data.status == 1)
                                            {
                                                layer.load(1, {
                                                    shade: [0.1, ''], //0.1透明度的白色背景
                                                    time: 500
                                                });
                                                setTimeout(function () {
                                                    layer.msg(data.message, {time: 1000}, function () {
                                                        window.location.href = "{:url('/manage')}";
                                                    });
                                                }, 500);
                                            } else
                                            {
                                                layer.load(1, {
                                                    shade: [0.1, ''], //0.1透明度的白色背景
                                                    time: 500
                                                });
                                                setTimeout(function () {
                                                    layer.msg(data.message, {time: 1000}, function () {

                                                    });
                                                }, 500);
                                            }
                                        })

                                        //layer.alert(JSON.stringify(checkedData), {shade: 0});
                                        //console.log(checkedData);
                                    }
                                    , setChecked: function () {
                                        tree.setChecked('demoId1', [12, 16]); //勾选指定节点
                                    }
                                    , reload: function () {
                                        //重载实例
                                        tree.reload('demoId1', {

                                        });

                                    }
                                });

                            });
                        </script>

                        <script>
                            $(".auth").on("click", function () {
                                var aid = $(this).val();
                                if (!$(this).is(":checked"))
                                {




                                } else
                                {
                                    $.post("{:url('Role/ajaxselects')}", {aid: aid}, function (data) {


                                        $("input[class='authf'][value='" + data + "']").prop('checked', true);
                                        $("input[class='authf'][value='" + data + "']").prop('checked');

                                    });

                                }
                            })


                            $(".authf").on("click", function () {
                                var fid = $(this).val();

                                if (!$(this).is(":checked"))
                                {
                                    //alert("取消");

//取消选择
                                    $.post("{:url('Role/ajaxselect')}", {fid: fid}, function (data) {


                                        for (key in data) {
                                            var v = data[key]['auth_id']
                                            $("input[class='auth'][value='" + v + "']").removeProp('checked');
                                            $("input[class='auth'][value='" + v + "']").prop('checked');
                                        }

                                    });
                                } else
//选择
                                {
                                    // alert("选择");
                                    $.post("{:url('Role/ajaxselect')}", {fid: fid}, function (data) {


                                        for (key in data) {
                                            var v = data[key]['auth_id']
                                            $("input[class='auth'][value='" + v + "']").prop('checked', true);
                                            $("input[class='auth'][value='" + v + "']").prop('checked');
                                        }

                                    })
                                }
                            })


                        </script>

                        <script>
//                            $(".save1").click(function () {
////                                 var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
////                                 alert(checkedData);
//                                 
//                                var formData = new FormData(document.getElementById("form2"));//表单id
////                                $.ajax({
////                                    type: "post",
////                                    url: "{:url('admin/Role/update')}",
////                                    data: formData,
////                                    async: false,
////                                    cache: false,
////                                    contentType: false,
////                                    processData: false,
////                                    dataType: 'json',
////                                    success: function (data) {
////
////                                        if (data.status == 1)
////                                        {
////                                            layer.load(1, {
////                                                shade: [0.1, ''], //0.1透明度的白色背景
////                                                time: 500
////                                            });
////                                            setTimeout(function () {
////                                                layer.msg(data.message, {time: 1000}, function () {
////                                                    window.location.href = "{:url('/manage')}";
////                                                });
////                                            }, 500);
////                                        } else
////                                        {
////                                            layer.load(1, {
////                                                shade: [0.1, ''], //0.1透明度的白色背景
////                                                time: 500
////                                            });
////                                            setTimeout(function () {
////                                                layer.msg(data.message, {time: 1000}, function () {
////
////                                                });
////                                            }, 500);
////                                        }
////                                    }
////                                })
//                            })
                        </script>
                    </div>

                </div>

            </div>
            <footer>
                <hr>

                <p class="pull-right">Collect from <a href="#" title="网页模板" >sxddd</a></p>


                <p>&copy; 2019 <a href="#" >Portnine</a></p>
            </footer>

        </div>
    </div>

</div>